﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// PaperTopic业务逻辑的简要说明。
    /// </summary>
    public class PaperTopic
    {
        /// <summary>
        /// 组织机构DAL
        /// </summary>
        private readonly DAL.PaperTopic dal = new DAL.PaperTopic();
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="fPaperId">编号（主键）</param>
        /// <returns>是否存在</returns>
        public bool ExistsPaperID(decimal fPaperId)
        {
            return dal.ExistsPaperID(fPaperId);
        }

        /// <summary>
        /// 题目修改保存 事务模式
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="topicModel">题目对象</param>
        /// <param name="answerOptionList">答案集合</param>
        public void UpdTopicAndAnswerOption(Model.PaperTopic topicModel, List<Model.PaperAnswerOption> answerOptionList)
        {
            dal.UpdTopicAndAnswerOption(topicModel, answerOptionList);
        }

        /// <summary>
        /// 批量删除题目和题目选择项 事务模式
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="topicIdList">编号集合</param>
        public void DelTopicAndAnswerOptionMany(List<decimal> topicIdList)
        {
            dal.DelTopicAndAnswerOptionMany(topicIdList);
        }

        /// <summary>
        /// 删除题目和题目选择项 事务模式
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="topicID">编号</param>
        public void DelTopicAndAnswerOption(decimal topicID)
        {
            dal.DelTopicAndAnswerOption(topicID);
        }


        /// <summary>
        ///  获得数据列表
        /// <creator>chenly</creator>
        /// <date>2013-7-16</date>
        /// </summary>
        /// <param name="dt">DataTable表</param>
        /// <returns>List集合</returns>
        public List<Model.PaperTopic> DataTableToListPaperTopic(DataTable dt)
        {
            List<Model.PaperTopic> modelList = new List<Model.PaperTopic>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.PaperTopic model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.PaperTopic();
                    if (dt.Rows[n]["FPaperId"].ToString() != string.Empty)
                    {
                        model.FPaperId = decimal.Parse(dt.Rows[n]["FPaperId"].ToString());
                    }
                    model.FTopic = dt.Rows[n]["FTopic"].ToString();
                    model.FTopicType = dt.Rows[n]["FTopicType"].ToString();
                    model.FPaperClsNo = dt.Rows[n]["FPaperClsNo"].ToString();
                    model.FTitle = dt.Rows[n]["FTitle"].ToString();
                    if (dt.Rows[n]["FPaperTopicId"].ToString() != string.Empty)
                    {
                        model.FPaperTopicId = decimal.Parse(dt.Rows[n]["FPaperTopicId"].ToString());
                    }    

                    modelList.Add(model);
                }
            }
            return modelList;
        }



        /// <summary>
        /// 保存题目和题目选择项 事务模式
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
        /// <param name="topicModel">题目对象</param>
        /// <param name="answerOptionList">答案集合</param>
        public void AddTopicAndAnswerOption(Model.PaperTopic topicModel, List<Model.PaperAnswerOption> answerOptionList)
        {
            dal.AddTopicAndAnswerOption(topicModel, answerOptionList);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        /// <creator>chenly</creator>
        /// <date>2013-7-25</date>
       /// <param name="fPaperTopicId">题目主题编号</param>
       /// <returns>Model对象</returns>
        public Model.PaperTopic GetModel(decimal fPaperTopicId)
        {

            return dal.GetModel(fPaperTopicId);
        }

    }
}
